import java.awt.BasicStroke;
import java.awt.Point;
import java.util.ArrayList;


/*
 * Draw manager class
 * 
 * Basic idea of how it works:
 * It keeps an arraylist of draws.
 * Every time you add to the arraylist of draws, it just does a .add onto the end.
 * Every time you want to remove from the arraylist, it doesn't actually remove, but
 * rather, nulls out where the old draw was. 
 * 
 * 
 * 
 */


public class DrawManager {
	private ArrayList<Draw> draws;
	private int currID;
	private int currentlyDragging;
	
	private Draw[]blankarray = new Draw[0];
	private BasicStroke drawStroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
	
	
	
	
	
	
	public DrawManager(){
		draws = new ArrayList<Draw>(20);
		currID = 0;
		currentlyDragging = -1;
		
		
	}
	
	public Draw[] getSnapshot(){
		return draws.toArray(blankarray);
	}
	
	public void getRidOf(Draw draw){
		draws.set(draw.id, null);
		
		if(draw.id == currentlyDragging){ //if the ID was that of the current one we were dragging
			releaseDragging();
		}
	}
	
	public void addNewDraw(Point p){
		draws.add(new Draw(p,p,currID,drawStroke));
		currentlyDragging = currID;
		currID++;
	}
	
	public void dragTo(Point p){
		//Mouse dragging will blindly call this method. It's up to the manager
		// to check if it can actually move something or not.
		
		if( currentlyDragging !=-1 && draws.get(currentlyDragging)!=null)
			draws.get(currentlyDragging).moveEndpointTo(p);
		
	}
	//Release the marker on what we were dragging.
	public void releaseDragging(){
		currentlyDragging = -1;
	}
	
	public void reset(){
		draws.clear();
		currID = 0;
		currentlyDragging = -1;
	}
	
	
}


